package mrdemo004;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class AvgMap  extends Mapper<LongWritable, Text, Text, IntWritable>{
	
	private Text val = new Text("");

	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, IntWritable>.Context context)
			throws IOException, InterruptedException {
		
		String line = value.toString();
		
		//输入的数据行，长度大于0则输出
		if(line!=null && line.trim().length()>0) {
			//解析处每一行的数据，按照 < 姓名, 成绩 > 输出
			String[] split = line.split("\t");
			if(split!=null && split.length == 2) {
				//符合数据的格式要求（应该再检查第二个数据项是整数）
				context.write(new Text(split[0]),new IntWritable(Integer.valueOf(split[1])));
			}
 		}
	}
}
